<?php if (!defined('BASEPATH')) exit('No direct script access allowed');  
/*
 * setTitle
 * rawHeaderHTML
 */
class codexTemplates{ 
    var $CI;
    var $asset_folder;
    var $doctype = "";
    var $head = "";
    var $title = "";
    var $body = "";
    var $footer = "";
    var $header = "";
    var $loaded_objects = array('js' => array(),
                                'inlineJS' => array(),
                                'css' => array(),
                                'inlineCSS' => array());

    function codexTemplates () { 
        $this->CI = &get_instance();
        $this->asset_folder = $this->CI->config->item('codex_asset_folder');
    }
    function docType ($type){ 
        switch($type){
            case "transitional":
                $this->doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                                "http://www.w3.org/TR/html4/loose.dtd">'."\n";
            break;
            case "strict":
                $this->doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                                "http://www.w3.org/TR/html4/strict.dtd">'."\n";
            break;
            default:
            break;
        }
    }
    function clearHTML(){ $this->doctype = ""; $this->head = ""; $this->body="";$this->footer=""; }

    function inlineJS ($identifier, $code){ 
        if(!in_array($identifier,$this->loaded_objects['inlineJS'])){
            $this->head .= '<script type="text/javascript">'.$code.'</script>'."\n";
            $this->loaded_objects['inlineJS'][] = $identifier;
        }
    }
    function inlineCSS ($identifier, $code){ 
        if(!in_array($identifier,$this->loaded_objects['inlineCSS'])){
            $this->head .= '<script type="text/css">'.$code.'</script>'."\n";
            $this->loaded_objects['inlineCSS'][] = $identifier;
        }
    }
    function js ($identifier, $file){ 
        if(!in_array($identifier,$this->loaded_objects['js'])){
            $this->head .= '<script type="text/javascript" src="'.$this->asset_folder.'js/'.$file.'"></script>'."\n";
            $this->loaded_objects['js'][] = $identifier;
        }
    }
    function css ($identifier, $file){ 
        if(!in_array($identifier,$this->loaded_objects['css'])){
            $this->head .= '<link rel="stylesheet" href="'.$this->asset_folder.'css/'.$file.'" type="text/css">'."\n";
            $this->loaded_objects['css'][] = $identifier;
        }
    }
    function setTitle ($new_val){ 
        $this->title = $new_val;
    }
    function rawHeaderHTML($html){
        $this->head .= $html;
    }
    function rawBodyHTML($html){
        $this->body .= $html;
    }
    function loadView ($file,$data=array()){ 
        $this->body .= $this->CI->load->view($file,$data,true);
    }
    function loadInlineView ($file,$data=array()){ 
        $this->CI->load->view($file,$data);
    }
    function _getHTML (){ 
        $html = <<<EOT
$this->doctype
<html>
    <head>
        <title>$this->title</title>
        $this->head
    </head>
    <body>
        $this->body
    </body>
</html>
EOT;
        return $html;
    }
    function fetchHTML (){ 
        return $this->_getHTML();
    }
    function printHTML(){
        echo $this->_getHTML();
    }
}
?>
